package com.vivimice.lotroller.demo;

import com.vivimice.lotroller.Lotroller;
import com.vivimice.lotroller.notification.NotificationAgent;

/**
 * Here defines all inter-component logic for this demo application
 * 
 * @author vivimice
 *
 */
public class DemoLotroller extends Lotroller {

	public DemoLotroller(NotificationAgent agent) {
		super(agent);
	}

	@Override
	protected void onCreate() {
		// This just a simple chaining rule. means when Demo.APP_START is notified, 
		// notify DemoFileSystemEmulator.ASYNC_LOAD_RESOURCES
		out(DemoFileSystemEmulator.ASYNC_LOAD_RESOURCES, in(DemoApp.APP_START));
		
		// Another simple chaining rule
		out(DemoNetworkingEmulator.ASYNC_LOAD_USER, in(DemoApp.APP_START));
		
		// This rule defines: when DemoFileSystemEmulator.RESOURCES_LOADED and
		// DemoNetworkingEmulator.USER_LOADED has both been notified, notify
		// DemoUI.SHOW_WELCOME
		out(DemoUI.SHOW_WELCOME, 
				and(
						in(DemoFileSystemEmulator.RESOURCES_LOADED),
						in(DemoNetworkingEmulator.USER_LOADED)
				));
	}

	@Override
	protected void onClose() {
		// This method will be called when is lotroller is closed manually
		// Usually, doing removeListener jobs here.
		// If this lotroller didn't manually added any listener to agent,
		// this method can just be a stub 
		
	}

}
